import 'package:flutter/material.dart';

class BaseTextAdaptiveWidthWidget extends StatelessWidget {
  /// 传入的文本
  final String text;

  /// 固定宽度 文本宽度，不包括后缀的宽度
  final double fixedWidth;

  final TextStyle textStyle;

  final String suffix;

  const BaseTextAdaptiveWidthWidget({Key key, @required this.text, @required this.fixedWidth, this.textStyle, this.suffix = ''}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisSize: MainAxisSize.min,
      children: [
        Container(
          constraints: BoxConstraints(maxWidth: fixedWidth, minWidth: fixedWidth),
          child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: _buildRowChildren()),
        ),
        Text(this.suffix, style: this.textStyle),
      ],
    );
  }

  List<Widget> _buildRowChildren() {
    return this.text.split('').map((e) => Text(e, style: this.textStyle)).toList();
  }
}
